package com.jt.tenant.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetNetData;
import com.jt.tenant.widget.Tools;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

/**
 * Created by Administrator on 2016/2/14.
 */
public class IntegralRechargeActivity extends JTActivity implements View.OnClickListener {

    private TextView title_name,pay;

    private TextView phone,nickname,surplus;

    private TextView recharge_10,recharge_50,recharge_100;

    private EditText recharge_number;

    private TextView recharge_price;

    private String tyjf;

    private double pay_price = 0.0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_integral_recharge);

        initView();

    }

    @Override
    protected void onResume() {

        super.onResume();

        tyjf = JTApplication.jtPreferences.readUserIntegral("2");

        surplus.setText("当前可用通用积分："+tyjf);

    }

    private void initView() {

        (title_name = (TextView) findViewById(R.id.tv_title_name)).setText("积分充值");

        (pay = (TextView)findViewById(R.id.tv_integral_recharge_go)).setOnClickListener(this);

        (phone = (TextView)findViewById(R.id.tv_integral_recharge_phone)).setText(JTApplication.jtPreferences.readPhone());

        (nickname = (TextView)findViewById(R.id.tv_integral_recharge_nickname)).setText(JTApplication.jtPreferences.readNickName());

        (surplus = (TextView)findViewById(R.id.tv_integral_recharge_surplus)).setText("当前可用通用积分："+tyjf);

        (recharge_10 = (TextView)findViewById(R.id.tv_integral_recharge_10)).setOnClickListener(this);

        (recharge_50 = (TextView)findViewById(R.id.tv_integral_recharge_50)).setOnClickListener(this);

        (recharge_100 = (TextView)findViewById(R.id.tv_integral_recharge_100)).setOnClickListener(this);

        recharge_number = (EditText)findViewById(R.id.et_integral_recharge_number);

        recharge_number.setOnClickListener(this);

        recharge_number.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {


            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                if(s.length()>0) {

                    recharge_price.setText(s.toString() + "元");

                    pay_price = Double.parseDouble(s.toString());

                }else {

                    recharge_price.setText("0元");

                    pay_price = 0;

                }

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        recharge_price = (TextView)findViewById(R.id.tv_integral_recharge_price);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.tv_integral_recharge_go:

                if(pay_price>0){

                startActivity(new Intent(this,GSPaymentActivity.class)

                        .putExtra("order_id", "BCBLL"+System.currentTimeMillis())

                        .putExtra("total_price", Tools.F_num(String.valueOf(pay_price)))

//                                .putExtra("total_price", "0.01")

                        .putExtra("flag", "5"));

                }else {

                    UtilToast.show(context,"充值数量不可为0");

                }



                break;

            case R.id.tv_integral_recharge_10:

                recharge_10.setBackgroundResource(R.drawable.round_ff6565_ffffff_1dp);

                recharge_10.setTextColor(getResources().getColor(R.color.MainColor));

                recharge_50.setBackgroundResource(R.drawable.round_757575_ffffff_1dp);

                recharge_50.setTextColor(getResources().getColor(R.color.HintColor));

                recharge_100.setBackgroundResource(R.drawable.round_757575_ffffff_1dp);

                recharge_100.setTextColor(getResources().getColor(R.color.HintColor));

                recharge_price.setText("10元");

                pay_price = 10;

                break;

            case R.id.tv_integral_recharge_50:

                recharge_10.setBackgroundResource(R.drawable.round_757575_ffffff_1dp);

                recharge_10.setTextColor(getResources().getColor(R.color.HintColor));

                recharge_50.setBackgroundResource(R.drawable.round_ff6565_ffffff_1dp);

                recharge_50.setTextColor(getResources().getColor(R.color.MainColor));

                recharge_100.setBackgroundResource(R.drawable.round_757575_ffffff_1dp);

                recharge_100.setTextColor(getResources().getColor(R.color.HintColor));

                recharge_price.setText("50元");

                pay_price = 50;


                break;

            case R.id.tv_integral_recharge_100:

                recharge_10.setBackgroundResource(R.drawable.round_757575_ffffff_1dp);

                recharge_10.setTextColor(getResources().getColor(R.color.HintColor));

                recharge_50.setBackgroundResource(R.drawable.round_757575_ffffff_1dp);

                recharge_50.setTextColor(getResources().getColor(R.color.HintColor));

                recharge_100.setBackgroundResource(R.drawable.round_ff6565_ffffff_1dp);

                recharge_100.setTextColor(getResources().getColor(R.color.MainColor));

                recharge_price.setText("100元");

                pay_price = 100;

                break;

            case R.id.et_integral_recharge_number:

                recharge_10.setBackgroundResource(R.drawable.round_757575_ffffff_1dp);

                recharge_10.setTextColor(Color.parseColor("#757575"));

                recharge_50.setBackgroundResource(R.drawable.round_757575_ffffff_1dp);

                recharge_50.setTextColor(Color.parseColor("#757575"));

                recharge_100.setBackgroundResource(R.drawable.round_757575_ffffff_1dp);

                recharge_100.setTextColor(Color.parseColor("#757575"));

                recharge_price.setText("");

                pay_price = 0;

                break;

        }

    }

}
